import java.awt.Component;
import java.awt.Dimension;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;

@SuppressWarnings("serial")
public class ArrowTest extends JSplitPane {
	private static final int PREF_W = 400;
	private static final int PREF_H = PREF_W;

	public ArrowTest() {
		ActionMap actionMap = getActionMap();
		int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
		InputMap inputMap = getInputMap(condition);

		for (Direction direction : Direction.values()) {
			inputMap.put(direction.getKeyStroke(), direction.getText());
			actionMap.put(direction.getText(),
					new MyArrowBinding(direction.getText()));
		}
	}

	private class MyArrowBinding extends AbstractAction {
		public MyArrowBinding(String text) {
			super(text);
			putValue(ACTION_COMMAND_KEY, text);
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			String actionCommand = e.getActionCommand();
			System.out.println("Key Binding: " + actionCommand);
		}
	}

	@Override
	public Dimension getPreferredSize() {
		return new Dimension(PREF_W, PREF_H);
	}

	private static void createAndShowGui() {
		ArrowTest mainPanel = new ArrowTest();

		JFrame frame = new JFrame("ArrowTest");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.getContentPane().add(mainPanel);

		JLabel leftComponent = new JLabel("test");
		leftComponent.setPreferredSize(new Dimension(100, 100));
		leftComponent.addMouseListener(mainPanel.new SimpleMouseListener(
				frame));

		JPanel rightComponent = new JPanel();
		rightComponent.setPreferredSize(new Dimension(100, 100));
		JTextField textField = new JTextField(20);
		 //textField.setFocusable(false);
		rightComponent.add(textField);

		mainPanel.setLeftComponent(leftComponent);
		mainPanel.setRightComponent(rightComponent);

		frame.pack();
		frame.setLocationByPlatform(true);
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGui();
			}
		});
	}

	private class SimpleMouseListener implements MouseListener {
		Component component;

		public SimpleMouseListener(Component component) {
			super();
			this.component = component;
		}

		public void mouseClicked(MouseEvent e) {
			component.requestFocusInWindow();
			System.out.println(KeyboardFocusManager
					.getCurrentKeyboardFocusManager().getFocusOwner());
		}

		public void mousePressed(MouseEvent e) {
		}

		public void mouseReleased(MouseEvent e) {
		}

		public void mouseEntered(MouseEvent e) {
		}

		public void mouseExited(MouseEvent e) {
		}
	}
}

enum Direction {
	UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)), DOWN("Down", KeyStroke
			.getKeyStroke(KeyEvent.VK_DOWN, 0)), LEFT("Left", KeyStroke
			.getKeyStroke(KeyEvent.VK_LEFT, 0)), RIGHT("Right", KeyStroke
			.getKeyStroke(KeyEvent.VK_RIGHT, 0)), A("A", KeyStroke
			.getKeyStroke(KeyEvent.VK_A, 0)), S("S", KeyStroke.getKeyStroke(
			KeyEvent.VK_S, 0));

	Direction(String text, KeyStroke keyStroke) {
		this.text = text;
		this.keyStroke = keyStroke;
	}

	private String text;
	private KeyStroke keyStroke;

	public String getText() {
		return text;
	}

	public KeyStroke getKeyStroke() {
		return keyStroke;
	}

	@Override
	public String toString() {
		return text;
	}
}